<!--
 * @FilePath: \vue-typescript-admin-template\src\views\dashboard\admin\components\PanelGroup.vue
 * @Author: maskMan
 * @Date: 2023-04-09 20:16:27
 * @LastEditTime: 2024-06-12 11:10:29
 * @Reference: 引用方 src\views\dashboard\admin\index.vue
 * @Descripttion: 说明 框架-主页-管理员首页-头部面板格子
-->

<template>
  <!-- 间隔40 -->
  <el-row :gutter="40" class="panel-group">
    <!-- xs 768 xm 992  md 1024 lg 1200 xl 1980 -->
    <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
      <!-- 访问人数 头像 -->
      <div class="card-panel" @click="handleSetLineChartData('newVisitis')">
        <div class="card-panel-icon-wrapper icon-people">
          <svg-icon name="peoples" class="card-panel-icon" />
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">总用户数</div>
          <!-- 数字滚动插件 -->
          <count-to
            :start-val="0"
            :end-val="people.c1"
            :duration="2600"
            class="card-panel-num"
          />
        </div>
      </div>
    </el-col>
    <!-- 留言人数 -->
    <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
      <div class="card-panel" @click="handleSetLineChartData('messages')">
        <div class="card-panel-icon-wrapper icon-message">
          <svg-icon name="guide" class="card-panel-icon" />
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">30日 新增</div>
          <count-to
            :start-val="0"
            :end-val="people.c2"
            :duration="3000"
            class="card-panel-num"
          />
        </div>
      </div>
    </el-col>
    <!-- 交易额 -->
    <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
      <div class="card-panel" @click="handleSetLineChartData('purchases')">
        <div class="card-panel-icon-wrapper icon-money">
          <svg-icon name="star" class="card-panel-icon" />
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">24时 新增</div>
          <count-to
            :start-val="0"
            :end-val="people.c3"
            :duration="3200"
            class="card-panel-num"
          />
        </div>
      </div>
    </el-col>
    <!-- 物品售出数 -->
    <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
      <div class="card-panel" @click="handleSetLineChartData('shoppings')">
        <div class="card-panel-icon-wrapper icon-shopping">
          <svg-icon name="back-top" class="card-panel-icon" />
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">7日 活跃数</div>
          <count-to
            :start-val="0"
            :end-val="people.c4"
            :duration="3600"
            class="card-panel-num"
          />
        </div>
      </div>
    </el-col>
  </el-row>
</template>

<script lang="ts">
import { Component, Vue } from 'vue-property-decorator'
import CountTo from 'vue-count-to' // Vue 数字滚动插件
import { getCounts } from '@/api/users';

@Component({
  name: 'PanelGroup',
  components: {
    CountTo
  }
})
export default class extends Vue {
   people = {
    c1:0,
    c2:0,
    c3:0,
    c4:0,
  }
  // 点击查看 Echars曲线图
  private handleSetLineChartData(type: string) {
    this.$emit('handle-set-line-chart-data', type)
  }
  
  mounted() {
    console.log('获取统计数据');
    getCounts().then((res:any)=>{
      if(res){
        console.log('统计数据',res);
        this.people=res
      }
    })
  }
}
</script>

<style lang="scss" scoped>
.panel-group {
  margin-top: 18px;

  .card-panel-col {
    margin-bottom: 32px;
  }

  .card-panel {
    height: 108px;
    cursor: pointer;
    font-size: 12px;
    position: relative;
    overflow: hidden;
    color: #666;
    background: #fff;
    box-shadow: 4px 4px 40px rgba(0, 0, 0, 0.05);
    border-color: rgba(0, 0, 0, 0.05);

    &:hover {
      .card-panel-icon-wrapper {
        color: #fff;
      }

      .icon-people {
        background: #40c9c6;
      }

      .icon-message {
        background: #36a3f7;
      }

      .icon-money {
        background: #f4516c;
      }

      .icon-shopping {
        background: #34bfa3;
      }
    }

    .icon-people {
      color: #40c9c6;
    }

    .icon-message {
      color: #36a3f7;
    }

    .icon-money {
      color: #f4516c;
    }

    .icon-shopping {
      color: #34bfa3;
    }

    .card-panel-icon-wrapper {
      float: left;
      margin: 14px 0 0 14px;
      padding: 16px;
      transition: all 0.38s ease-out;
      border-radius: 6px;
    }

    .card-panel-icon {
      float: left;
      font-size: 48px;
    }

    .card-panel-description {
      float: right;
      font-weight: bold;
      margin: 26px;
      margin-left: 0px;

      .card-panel-text {
        line-height: 18px;
        color: rgba(0, 0, 0, 0.45);
        font-size: 16px;
        margin-bottom: 12px;
      }

      .card-panel-num {
        font-size: 20px;
      }
    }
  }
}

@media (max-width: 550px) {
  .card-panel-description {
    display: none;
  }

  .card-panel-icon-wrapper {
    float: none !important;
    width: 100%;
    height: 100%;
    margin: 0 !important;

    .svg-icon {
      display: block;
      margin: 14px auto !important;
      float: none !important;
    }
  }
}
</style>
